<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <button id="btn">点我一下</button>
    <script>
        const btn = document.querySelector('#btn');
       btn.addEventListener('click',function(){
          /*    //定时器
          // 例如，生成1到10之间的一个随机整数
               
            setTimeout(()=>{
                function getRandomInt(min, max) {
  min = Math.ceil(min);
  max = Math.floor(max);
  return Math.floor(Math.random() * (max - min + 1)) + min;
}
 
 
                //100 里面抽到前30中奖
                let n = getRandomInt(1,100) //随机数
                console.log(n);
                if(n<=30){
                    alert('恭喜您中奖了')
                }else{
                    alert('再接再厉')
                }
            },1000)
        
        }) */



        //promise 
        const p = new Promise((resolve,reject)=>{
            setTimeout(()=>{
                function getRandomInt(min, max) {
  min = Math.ceil(min);
  max = Math.floor(max);
  return Math.floor(Math.random() * (max - min + 1)) + min;
}
 
 
                //100 里面抽到前30中奖
                let n = getRandomInt(1,100) //随机数
                console.log(n);
                
                if(n<=30){
                    resolve(n);
                }else{
                    reject(n);
                }
            },1000


            )
        });
        p.then((value)=>{
            alert("你中奖了"+value)
        },()=>{
            alert("没中奖")
        })

       })
    </script>
</body> 
</html>